//
//  StoreView.m
//  YiShangPin
//
//  Created by 衣尚品1 on 15/3/16.
//  Copyright (c) 2015年 yishangpin2. All rights reserved.
//

#import "StoreView.h"
#import "AppDelegate.h"

@implementation StoreView{
    AppDelegate *delegate;
    CGContextRef context;
    float Y1;
    float Y2;
}



// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    
    delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    //创建画布
    context = UIGraphicsGetCurrentContext();
    //设置线条颜色
    [[UIColor grayColor] set];
    //设置线条宽度
    CGContextSetLineWidth(context, 0.3f);
    
    delegate.isHaveHeight = NO;
    [self addView4];
    
    CGPoint newPoints[] = {
        CGPointMake(delegate.width/3, 30),
        CGPointMake(delegate.width/3, Y2),
    };
    CGContextAddLines(context, newPoints, 2);
    
    CGPoint newpoints1[] = {
        CGPointMake(20, Y1),
        CGPointMake(delegate.width-20, Y1),
    };
    CGContextAddLines(context, newpoints1, 2);
    
    CGContextStrokePath(context);
}

- (float)addView4{
    
    UIFont *lableFont = [UIFont fontWithName:@"TimesNewRomanPS-ItalicMT" size:16];
    
    delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 20, 20)];
    image.image = [UIImage imageNamed:@"storeDetails.png"];
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 150, 18)];
    label1.text = @"Store Details";
    label1.font = [UIFont fontWithName:@"TimesNewRomanPS-BoldItalicMT" size:18];
    //    label1.font = [UIFont boldSystemFontOfSize:16.0f];
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(delegate.width-80, 0, 80, 18)];
    [button setTitle:@"Visit Store" forState:0];
    button.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    [button setTitleColor:[UIColor colorWithRed:47.f/255 green:164.f/255 blue:230.f/255 alpha:1] forState:0];
    
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(30, 40, delegate.width/3-40, 20)];
    label2.text = @"Store";
    label2.font = lableFont;
    //    label2.backgroundColor = [UIColor redColor];
    
    UILabel *label3 = [[UILabel alloc] init];
    label3.numberOfLines = 0;
    label3.lineBreakMode = NSLineBreakByWordWrapping;
    label3.text = @"Lolita UK";
    label3.font = lableFont;
    CGSize size1 = [label3.text boundingRectWithSize:CGSizeMake(delegate.width/3*2-40, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:label3.font,NSFontAttributeName, nil] context:nil].size;
    label3.frame = CGRectMake(delegate.width/3+10, 40, delegate.width/3*2-40, size1.height);
    //    label3.backgroundColor = [UIColor redColor];
    
    Y1 = 50+size1.height;
    
    UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(30, 60+size1.height, delegate.width/3-40, 45)];
    label4.text = @"Store Rating";
    label4.numberOfLines = 2;
    label4.font = lableFont;
    label4.lineBreakMode = NSLineBreakByWordWrapping;
    //    label4.backgroundColor = [UIColor redColor];
    
    UIImageView *starIamge = [[UIImageView alloc] initWithFrame:CGRectMake(delegate.width/3+10, 60+size1.height, 100, 15)];
    starIamge.image = [UIImage imageNamed:@"star.png"];
    
    UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(delegate.width/3+10, 80+size1.height, 105, 18)];
    [button1 setTitle:@"View all ratings" forState:0];
    [button1 setTitleColor:[UIColor blueColor] forState:0];
    button1.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    [button1 setTitleColor:[UIColor colorWithRed:47.f/255 green:164.f/255 blue:230.f/255 alpha:1] forState:0];
    
    Y2 = 115+size1.height;
    
    if (delegate.isHaveHeight == NO) {
        [self addSubview:image];
        [self addSubview:label1];
        [self addSubview:button];
        [self addSubview:label2];
        [self addSubview:label3];
        [self addSubview:label4];
        [self addSubview:starIamge];
        [self addSubview:button1];
    }
    
    return size1.height+130;
}


@end
